/
page.tsx
53 lines (46 loc) · 1.36 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use client";
import { RoomProvider, useThreads } from "../../../liveblocks.config";
import { Loading } from "../../components/Loading";
import { Composer, Thread } from "@liveblocks/react-comments";
import { ClientSideSuspense } from "@liveblocks/react";
import { ErrorBoundary } from "react-error-boundary";
import { useExampleRoomId } from "../../example.client";
import { Suspense } from "react";
/**
* Displays a list of threads, along with a composer for creating
* new threads.
*/
function Example() {
const { threads } = useThreads();
return (
<div className="threads">
{threads.map((thread) => (
<Thread key={thread.id} thread={thread} className="thread" />
))}
<Composer className="composer" />
</div>
);
}
function Room({ room }: { room: string }) {
const roomId = useExampleRoomId(room);
return (
<RoomProvider id={roomId} initialPresence={{}}>
<ErrorBoundary
fallback={
<div className="error">There was an error while getting threads.</div>
}
>
<ClientSideSuspense fallback={<Loading />}>
{() => <Example />}
</ClientSideSuspense>
</ErrorBoundary>
</RoomProvider>
);
}
export default function Page({ params }: { params: { room: string } }) {
return (
<Suspense fallback={<Loading />}>
<Room room={params.room} />
</Suspense>
);
}